package com.library.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.library.common.base.ApiResult;
import com.library.entity.BookUserEntity;
import com.library.entity.dto.Time;
import com.library.entity.vo.townshipUserStatisticsVo;
import com.library.service.informationStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@RequestMapping("/informationStatistics")
@Api(tags = "信息统计接口", value = "信息统计接口")
public class informationStatisticsController {

	@Resource
	private informationStatisticsService service;

	@ApiOperation(value = "总用户量")
	@GetMapping("/totalUsers")
	public ApiResult totalUsers(BookUserEntity bookUser) {
		return service.totalUsers(bookUser);
	}

	@ApiOperation(value = "日/月/浏览量")
	@GetMapping("/browsePage")
	public ApiResult browseList() {
		return service.browseList();
	}

	@ApiOperation(value = "注册村的数量")
	@GetMapping("/registerList")
	public ApiResult registerList(BookUserEntity bookUser) {
		return service.registerList(bookUser);
	}

	@ApiOperation(value = "人 管理员")
	@GetMapping("/peopleList")
	public ApiResult peopleList(BookUserEntity bookUser) {
		return service.peopleList(bookUser);
	}

	@ApiOperation(value = "资源分析")
	@GetMapping("/resourceAnalysis")
	public ApiResult resourceAnalysis(BookUserEntity bookUser) {
		return service.resourceAnalysis();
	}

	@ApiOperation(value = "访问来源")
	@GetMapping("/accessSource")
	public ApiResult accessSource(BookUserEntity bookUser) {
		return service.accessSource();
	}

	@ApiOperation(value = "统计新增用户")
	@PostMapping(value = "/getNewUsers")
	public ApiResult getNewUsers(@RequestBody Time time) {
		return service.getNewUsers(time.getStartTime(), time.getEndTime());
	}

	@ApiOperation(value = "各区人员统计")
	@GetMapping(value = "/numberPeople")
	public ApiResult numberPeople(Page page, String name) {
		return service.numberPeople(page, name);
	}

	@ApiOperation(value = "活跃地区统计")
	@GetMapping(value = "/activeArea")
	public ApiResult activeArea(Page page, String name) {
		return service.activeArea(page, name);
	}

	@ApiOperation(value = "乡镇用户统计")
	@GetMapping(value = "/townshipUserStatistics")
	public ApiResult townshipUserStatistics(Page page, townshipUserStatisticsVo townshipUserStatisticsVo) {
		List<townshipUserStatisticsVo> townshipUserStatisticsVos = service.townshipUserStatistics(page, townshipUserStatisticsVo);
		if (townshipUserStatisticsVo==null){
			return ApiResult.failed("没有权限");
		}
		return ApiResult.ok(page.setRecords(townshipUserStatisticsVos));
	}

	/**
	 * 导出excel 表格
	 * @return excel 文件流
	 */
	@GetMapping("/townshipUserStatistics/export")
	public List<townshipUserStatisticsVo> export(townshipUserStatisticsVo townshipUserStatisticsVo) {
		return service.townshipUserStatistics(null,townshipUserStatisticsVo);
	}

	@GetMapping(value = "/Statistics")
	public Map Statistics() {
		return service.Statistics();
	}
}
